let app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    storeId:null,
    storeDetail:{},
    workWeek:[ //显示选中的日期数组
      {
        title: '周一',
        value: '1'
      },
      {
        title: '周二',
        value: '2'
      },
      {
        title: '周三',
        value: '3'
      },
      {
        title: '周四',
        value: '4'
      },
      {
        title: '周五',
        value: '5'
      },
      {
        title: '周六',
        value: '6'
      },
      {
        title: '周日',
        value: '7'
      }
    ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if((options.storeId??'') !== '') {
      this.data.storeId = parseInt(options.storeId);
    }
    this.storeDetail();
  },
  storeDetail() {
    let that = this;
    let urlStr = app.getNetAddresss("plugin.coupon-store.frontend.store.storeDetail");
    let json = {
      store_id: this.data.storeId,
    };
    app._postNetWork({
      url: urlStr,
      data:json,
      success: function (resdata) {
        let res = resdata.data;
        if (res.result == 1) {
          let addressDetail = `${res.data.province}${res.data.city}${res.data.district}${res.data.street}${res.data.address}`,
              workWeek = res.data.work_week,
              workWeekData = that.data.workWeek,
              weekList =[];
              weekList = workWeekData.filter(item => workWeek.indexOf(item.value) > -1);
          let workTimeTitle =  `${weekList[0].title}至${weekList[weekList.length -1].title}`;
          that.setData({
            storeDetail: res.data,
            addressDetail: addressDetail,
            workTime: workTimeTitle
          })
        } else {
          wx.showToast({
            icon: 'none',
            title: res.msg,
            duration: 1500
          });
        }
      },
      fail: function (res) {
        console.log(res);
      }
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})